﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections;

namespace Dadjai.Common
{
    public static class FileManager
    {
        public static string[] GetData(string fileName, Encoding encoding)
        {
            List<string> data = new List<string>();
            try
            {
                using (BinaryReader r = new BinaryReader(File.Open(string.Format(@"../../../DATA/{0}", fileName), FileMode.Open), encoding))
                {
                    while (true)
                    {
                        data.Add(r.ReadString());
                    }
                }
            }
            catch
            {
                // END OF FILE HAS BEEN REACHED
            }
            return data.ToArray();
        }

        public static void StoreData(string fileName, string[] data, Encoding encoding)
        {
            using (BinaryWriter w = new BinaryWriter(File.Open(string.Format(@"../../../DATA/{0}", fileName), FileMode.Create), encoding))
            {
                for (int i = 0; i < data.Length; i++)
                {
                    w.Write(data[i]);
                }
            }
        }
    }
}
